package com.jmlee.service.impl;

import com.jmlee.mapper.AStatisticsMapper;
import com.jmlee.pojo.ThisMonthWeekDate;
import com.jmlee.pojo.TimeUpDown;
import com.jmlee.service.AStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

@Service
public class AStatisticsServiceImpl implements AStatisticsService {

    @Autowired(required = false)
    private AStatisticsMapper aStatisticsMapper;

    //====================================统计======================================================

    /**
     * 用户统计
     * @author  xl W
     * @date 2021/3/14 21:06
     */
    //用户统计每周
    @Override
    public List<Integer> userWeek(String[] date) {
        List<Integer> count=new ArrayList<>();

        for(int i=0;i<date.length;i++){

            Integer t=  aStatisticsMapper.userWeekCount(date[i] );

            count.add(t);

        }
        return count;
    }
    //用户统计当前月
    @Override
    public List<Integer> userMonth() {

        List<TimeUpDown> zxsMonth= ThisMonthWeekDate.getzxsMonth();
        List<Integer> count=new ArrayList<>();
        for(int i=0;i<zxsMonth.size();i++){

            Integer t=  aStatisticsMapper.userMonthCount(zxsMonth.get(i).getStartTime(),zxsMonth.get(i).getEndTime());

            count.add(t);

        }
        return count;
    }
    //用户统计半年
    @Override
    public List<Integer> userYears( ) {

        List<TimeUpDown> zxsYe= ThisMonthWeekDate.getBanYearsMonth();
        List<Integer> count=new ArrayList<>();
        for(int i=zxsYe.size()-1;i>=0;i--){

            Integer t=  aStatisticsMapper.userBanYearCount(zxsYe.get(i).getStartTime(),zxsYe.get(i).getEndTime());

            count.add(t);

        }
        return count;

    }
    /**
     * 用户订单
     * @author  xl W
     * @date 2021/3/14 21:07
     */
    //订单统计每周
    @Override
    public List<Integer> ordersWeek(String[] date,Long  id ) {
        List<Integer> count=new ArrayList<>();

        for(int i=0;i<date.length;i++){

            Integer t=  aStatisticsMapper.ordersWeekCount(date[i],id);

            count.add(t);

        }
        return count;
    }
    //订单统计当前月
    @Override
    public List<Integer> ordersMonth(Long  id ) {

        List<TimeUpDown> zxsMonth= ThisMonthWeekDate.getzxsMonth();
        List<Integer> count=new ArrayList<>();
        for(int i=0;i<zxsMonth.size();i++){

            Integer t=  aStatisticsMapper.ordersMonthCount(zxsMonth.get(i).getStartTime(),zxsMonth.get(i).getEndTime(),id);

            count.add(t);

        }
        return count;
    }
    //订单统计半年
    @Override
    public List<Integer> ordersYears(Long  id ) {

        List<TimeUpDown> zxsYe= ThisMonthWeekDate.getBanYearsMonth();
        List<Integer> count=new ArrayList<>();
        for(int i=zxsYe.size()-1;i>=0;i--){

            Integer t=  aStatisticsMapper.ordersBanYearCount(zxsYe.get(i).getStartTime(),zxsYe.get(i).getEndTime(),id);

            count.add(t);

        }
        return count;

    }
    /**
     * 商品销量统计
     * @author  xl W
     * @date 2021/3/15 9:24
     */
    //销量统计每周
    @Override
    public List<Integer> salesWeek(String[] date, Long   id) {
        List<Integer> count=new ArrayList<>();

        for(int i=0;i<date.length;i++){

            Integer t=  aStatisticsMapper.salesWeekCount(date[i],id);

            count.add(t);

        }
        return count;
    }
    //销量统计当前月
    @Override
    public List<Integer> salesMonth(Long  id) {

        List<TimeUpDown> zxsMonth= ThisMonthWeekDate.getzxsMonth();
        List<Integer> count=new ArrayList<>();
        for(int i=0;i<zxsMonth.size();i++){

            Integer t=  aStatisticsMapper.salesMonthCount(zxsMonth.get(i).getStartTime(),zxsMonth.get(i).getEndTime(),id);

            count.add(t);

        }
        return count;
    }
    //销量统计半年
    @Override
    public List<Integer> salesYears(Long  id) {

        List<TimeUpDown> zxsYe= ThisMonthWeekDate.getBanYearsMonth();
        List<Integer> count=new ArrayList<>();
        for(int i=zxsYe.size()-1;i>=0;i--){

            Integer t=  aStatisticsMapper.salesBanYearCount(zxsYe.get(i).getStartTime(),zxsYe.get(i).getEndTime(),id);

            count.add(t);

        }
        return count;

    }

}
